const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    trainPlan: {
      trainDemand: []
    },
    hasSetPlan: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const that = this;
    const openId = app.globalData.openId;
    const url = app.globalData.url;
    //提取健身计划
    wx.request({
      url: url + '/train/trainPlan/' + openId,
      success: function (response) {
        if (response.data.success) {
          const trainPlan = response.data.content || {};
          const hasSetPlan = trainPlan.trainDemand && trainPlan.trainDemand.length > 0;
          that.setData({
            trainPlan: trainPlan,
            hasSetPlan: hasSetPlan
          });
        }
      }
    })
  },
  addPlan:function(){
    const trainPlan = this.data.trainPlan;
    wx.setStorageSync("trainPlan", JSON.stringify(trainPlan));
    wx.navigateTo({
      url: '/pages/trainDemand/trainDemand',
    })
  },
  editPlan:function(){
    const trainPlan = this.data.trainPlan;
    wx.setStorageSync("trainPlan", JSON.stringify(trainPlan));
    wx.navigateTo({
      url: '/pages/trainDemand/trainDemand',
    })
  }
})